import {deleteCourse, insertOneCourse, lookCourse, updateOneCourse} from '@/api/course'

const getDefaultState = () => {
}

const state = getDefaultState()

const mutations = {}

const actions = {
  // 条件查询
  async lookCourse({state}, course) {
    return new Promise((resolve, reject) => {
      lookCourse(course)
        .then((response) => {
          resolve(response)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 添加一条课程
  async insertOneCourse({state}, course) {
    return new Promise((resolve, reject) => {
      insertOneCourse(course)
        .then((response) => {
          resolve(response)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 修改课程
  async updateOneCourse({state}, course) {
    return new Promise((resolve, reject) => {
      updateOneCourse(course)
        .then((response) => {
          resolve(response)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 批量删除课程
  async deleteCourses({state}, ids) {
    return new Promise((resolve, reject) => {
      deleteCourse(ids)
        .then((response) => {
          resolve(response)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
}
